package com.example.batch.controller;

import com.example.batch.entity.User;
import com.example.batch.mapper.batch.UserMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/v1/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping
    public ResponseEntity<?> test() {
        List<User> user1List = new ArrayList<>();
        List<User> user2List = new ArrayList<>();
        for (int i = 1; i <= 50000; i++) {
            User user = new User();
            user.setName("name" + i);
            user.setDataStatus(1);
            user.setAge(i);
            user1List.add(user);
        }
        Long begin = System.currentTimeMillis();
        userMapper.insert(user1List);
        Long end = System.currentTimeMillis();
        System.out.println("1 times: " + (end - begin));
        for (int i = 50001; i <= 100000; i++) {
            User user = new User();
            user.setName("name" + i);
            user.setDataStatus(1);
            user.setAge(i);
            user2List.add(user);
        }
        begin = System.currentTimeMillis();
        userMapper.insert(user2List);
        end = System.currentTimeMillis();
        System.out.println("2 times: " + (end - begin));

        begin = System.currentTimeMillis();
        userMapper.insertList(user1List);
        end = System.currentTimeMillis();
        System.out.println("3 times: " + (end - begin));
        return ResponseEntity.ok("test");
    }
}
